﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

namespace HZ.Supervise.Web.Secondphase.Stocks
{
    public partial class Stocks_Group_Com : System.Web.UI.Page
    {
        StringBuilder sqlwhere;
        string goodsid;
        public string ProductName;
        IBLL.IBLL_Stocks ibs = BLLFactory.IBLL_Stocks();
        protected void Page_Load(object sender, EventArgs e)
        {
            goodsid = Request["goodsid"];
            if (!IsPostBack)
            {
                dateBind();
            }
        }

        private void dateBind()
        {
            int i = 0;
            sqlwhere = new StringBuilder();
            if ( string.IsNullOrEmpty(goodsid))
            {
                HZ.Web.WebUtil.Alert("数据异常,请返回重试!");
                return;
            }
            else
            {
                sqlwhere.Append(" and GoodsID = '" + goodsid + "'");
            }
            if (!string.IsNullOrEmpty(txtComName.Text.Trim()))
            {
                sqlwhere.Append(" and CompanyName like '%" + HZ.Supervise.DAL.DAL_Helper.Replace(txtComName.Text.Trim()) +"%'");
            }
            sqlwhere.Append(" order by CompanyTotalStock " + DropDownList1.SelectedValue);
            DataTable dt = ibs.GetComTotalStock(sqlwhere.ToString(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out i);
            if (dt.Rows.Count>0)
            {
                ProductName = dt.Rows[0]["ProductName"].ToString();
            }
            gvwInfo.AutoGenerateColumns = false;
            gvwInfo.DataSource = dt;
            AspNetPager1.RecordCount = i;
            gvwInfo.DataBind();

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            dateBind();
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }
    }
}
